Skip to content

Phase 2 , getting Apache 5 compilation and Junit ready along with clearing Checkstyles and spotbug issues #6100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: feature/master/apache5x
Choose a base branch
from

Conversation

joviegas
Copy link
Contributor

This PR is continuation of migrating the Apache 4 client

  • In this PR we are fixing the compilation error which occured during baseling
  • Making sure basic test cases are passing

Motivation and Context

Modifications

Testing

  • maven build with checkstyle and spotbugs

License

  • I confirm that this pull request can be released under the Apache 2 license

@joviegas joviegas requested a review from a team as a code owner May 13, 2025 17:23
@@ -152,7 +152,9 @@ public void run() {

for (Map.Entry<HttpClientConnectionManager, Long> entry : connectionManagers.entrySet()) {
try {
entry.getKey().closeIdleConnections(entry.getValue(), TimeUnit.MILLISECONDS);
entry.getKey().close(CloseMode.GRACEFUL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets add a todo here to keep track of close_idle_connection_timeout config. We will need to figure out how to support it with Apache5 if we can't do it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added JAVA-8272 will handle all IM issues in upcoming PR before starting working on test suites

@@ -250,20 +250,28 @@ public void abort() {
public void close() {
HttpClientConnectionManager cm = httpClient.getHttpClientConnectionManager();
IdleConnectionReaper.getInstance().deregisterConnectionManager(cm);
cm.shutdown();
// TODO : need to add test cases for this
cm.close(CloseMode.IMMEDIATE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, what are the other options?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CloseMode.java

public enum CloseMode {

    IMMEDIATE, GRACEFUL

}

Comment on lines +263 to +265
// TODO : This is required since Apache5 closes streams immediately, check memory impacts because of this.
if (response.getEntity() != null) {
response.setEntity(new BufferedHttpEntity(response.getEntity()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this seems odd. We should not buffer the entire stream.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeap I agree , but as mentioned in

The use of an HTTP response handler guarantees that the underlying HTTP connection will be released back to the connection manager automatically in all cases.

https://hc.apache.org/httpcomponents-client-5.4.x/examples.html

Thus we need to buffer the stream , we need to find a way around this or some better approach.

@@ -596,12 +606,12 @@ public void setDnsResolver(DnsResolver dnsResolver) {
}

@Override
public Builder socketFactory(ConnectionSocketFactory socketFactory) {
public Builder socketFactory(SSLConnectionSocketFactory socketFactory) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason we are changing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/apache/httpcomponents-client/blob/4021b7c47914efaf9cf30b8d00bbd129295c0639/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java#L122-L127

public final PoolingHttpClientConnectionManagerBuilder setSSLSocketFactory(
        final org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory sslSocketFactory) {
    this.tlsSocketStrategy = (socket, target, port, attachment, context) ->
            (SSLSocket) sslSocketFactory.createLayeredSocket(socket, target, port, context);
    return this;
}

PoolingHttpClientConnectionManagerBuilder only accepts LayeredConnectionSocketFactory thus we need to do it.

if (!firstAttempt && isRepeatable()) {
content.reset();
if (!firstAttempt && isRepeatableStream()) {
getContent().reset();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason we are calling getContent() instead of saving it as a member variable? ContentStreamProvider#newStream could be very expensive for some custom implementations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants